package com.example.demo.designpattern设计模式.behavioral行为型.chainofresponsibility责任链模式.二次手撕;

public class HanderChain {

    private Handler head = null;
    private Handler tail = null;

    public void addHandler(Handler handler) {
        handler.setSuccessor(null);

        if (head == null){
            head = handler;
            tail = handler;
            return;
        }

        tail.setSuccessor(handler);
        tail = handler;
    }

    public void handle() {
        if (head != null) {
            head.handler();
        }
    }

}
